﻿#include "EventApplication.hpp"
#include "EventApplicationWindow.hpp"
#include "EventButton.hpp"
#include "EventEntryBox.hpp"
#include "EventEntry.hpp"
#include "EventListUtils.hpp"

#include <iostream>
#include <exception>
#include <glibmm/markup.h>
#include <giomm/iostream.h>

Event::Application::Application()
{
    static_cast<void>(Event::Button());
    static_cast<void>(Event::EntryBox());
}

Glib::RefPtr<Event::Application>
Event::Application::create()
{
    return Glib::make_refptr_for_instance<Event::Application>(
        new Event::Application);
}

Event::ApplicationWindow *
Event::Application::create_appwindow()
{
    auto window = Event::ApplicationWindow::create();
    //auto window = Gtk::make_managed<Event::ApplicationWindow>();

    this->add_window(*window);
    window->signal_hide().connect(
        [window](void) { delete window; }
    );
    return window;
}

static void
test_something()
{
    std::cout << "Test Something...\n";

    //auto list = std::make_shared<Event::List<int>>(std::make_shared<int>(64), Event::Type::EVENT_TYPE_INT32);
    auto _list = new Event::List<bool>(std::make_shared<bool>(false), Event::Type::EVENT_TYPE_UINT8);
    auto& list = *_list;
    //Event::List<int> list(std::make_shared<int>(63), Event::Type::EVENT_TYPE_UINT8);

    list.add_data("test_string\n");
    list.iteration_reset();
    auto var = list.iteration_get();
    auto x   = var->get_type();
    std::cout << "Type1 is " << x << std::endl;
    auto var2 = list.iteration_get();
    auto y = var2->get_type();
    std::cout << "Type2 is " << y << std::endl;

    std::cout << "Test finished.\n";
}

void
Event::Application::on_activate()
{
    test_something();
    try
    {
        auto app_window = create_appwindow();
        app_window->present();
    }
    catch (const Glib::Error &ex)
    {
        std::cerr << "Event::Application::on_activate(): " <<
            ex.what() << std::endl;
    }
    catch (const std::exception &ex)
    {
        std::cerr << "Event::Application::on_activate(): " <<
            ex.what() << std::endl;
    }
}
